package org.vectrics.common.util;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import org.vectrics.SystemException;


public class LocalMachineUtils {
	public List findAddresses()	{
		List addresses = new ArrayList();
		try {
			Enumeration e1 = NetworkInterface.getNetworkInterfaces();
			while(e1.hasMoreElements()) {
				NetworkInterface ni = (NetworkInterface)e1.nextElement();
				
				System.out.print(ni.getName());
				Enumeration e2 = ni.getInetAddresses();
				while(e2.hasMoreElements()) {
					InetAddress ia = (InetAddress)e2.nextElement();
					addresses.add(ia.toString());
				}
			}
		} catch (Exception ex) {
			throw new SystemException("Exception finding network card addresses", ex);
		}
		return addresses;
	}
	
	public static String findHostName() {
        try {
            return InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            return "unknown";
        }
    }
	public static String findHostAddress() {
        try {
            return InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            return "Unknown Host Name";
        }
    }
	
}
